package org.mat.ipaas.ucenter.bff.admin.modules.message.controller;

import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.message.SysMessageRestAPI;
import org.mat.ipaas.ucenter.service.dto.message.entity.SysMessageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 消息
 */
@Slf4j
@RestController
@RequestMapping("/sys/message/sysMessage")
public class SysMessageController {

    @Autowired
    private SysMessageRestAPI sysMessageRestAPI;

    /**
     * 分页列表查询
     *
     * @param sysMessageDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/list")
    public MatApiResponse<?> queryPageList(SysMessageDTO sysMessageDTO,
                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.queryPageList(sysMessageDTO, pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 添加
     *
     * @param sysMessageDTO
     * @return
     */
    @PostMapping(value = "/add")
    public MatApiResponse<?> add(@RequestBody SysMessageDTO sysMessageDTO) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.add(sysMessageDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysMessageDTO
     * @return
     */
    @PutMapping(value = "/edit")
    public MatApiResponse<?> edit(@RequestBody SysMessageDTO sysMessageDTO) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.edit(sysMessageDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete")
    public MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public MatApiResponse<?> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 导出excel
     */
    @GetMapping(value = "/exportXls")
    public ModelAndView exportXls(SysMessageDTO sysMessageDTO) {
        ModelAndView modelAndView = sysMessageRestAPI.exportXls(sysMessageDTO);
        return modelAndView;
    }

    /**
     * excel导入
     *
     * @return
     */
    @PostMapping(value = "/importExcel")
    public MatApiResponse<?> importExcel() {
        MatApiResponse<?> matApiResponse = sysMessageRestAPI.importExcel();
        return matApiResponse;
    }

}
